
#include "command.h"

int _echo(char *argv[])
{
	/* check the number of cmd-line parameters is correct */
	int argc = 0;
	for (char **ptr = argv; *ptr != NULL; ptr++)
		argc++;

	if (argc < 2) {
		fprintf(stderr, "Usage: echo string\n");
		return -1;
	}

    // Print all arguments from argv[1] onwards, separated by spaces
    for (int i = 1; argv[i] != NULL; i++) {
        printf("%s", argv[i]);
        if (argv[i + 1] != NULL) { // Check if the next argument exists
            printf(" "); // Print a space between words
        }
    }
	printf("\n");

	return 0;
}
